import { wcf} from '../../proto-generated/wcf';

export type RawMessage = wcf.IWxMsg;

export class Message {
  constructor(private readonly message: wcf.IWxMsg) {}

  get raw(): RawMessage {
    return this.message;
  }

  get id() {
    return this.message.id;
  }

  get type() {
    return this.message.type;
  }

  get isSelf() {
    return this.message.isSelf;
  }

  isAt(wxid: string) {
    if (!this.isGroup) {
      return false;
    }
    if (
      !new RegExp(`<atuserlist\\>.*(${wxid}).*</atuserlist>`).test(
        this.xml!
      )
    ) {
      return false;
    }
    return !/@(?:所有人|all|All)/.test(this.message.content ?? '');
  }

  get xml() {
    return this.message.xml;
  }

  get isGroup() {
    return this.message.isGroup;
  }

  get roomId() {
    return this.message.roomid;
  }

  get content() {
    return this.message.content;
  }

  get sender() {
    return this.message.sender;
  }
}
